package cn.wubo.soap;

import cn.wubo.soap.model.Book;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Component
public class BookRepository {

    private static final Map<String, Book> books = new HashMap<>();

    @PostConstruct
    public void initData() {

        Book book = new Book();
        book.setName("AAAAA");
        book.setSn("AAAAA");
        book.setPrice(new BigDecimal("111.11"));
        books.put(book.getName(), book);

        book = new Book();
        book.setName("BBBBB");
        book.setSn("BBBBB");
        book.setPrice(new BigDecimal("222.22"));
        books.put(book.getName(), book);

        book = new Book();
        book.setName("CCCCC");
        book.setSn("CCCCC");
        book.setPrice(new BigDecimal("333.33"));
        books.put(book.getName(), book);
    }

    public Book findBook(String name) {
        Assert.notNull(name, "The Student's name must not be null");
        return books.get(name);
    }
}
